package com.aaa.controller.scl;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.*;
import com.aaa.entity.fpa.QuestionFpa;
import com.aaa.entity.scl.QuestionScl;
import com.aaa.entity.systemmanage.User;
import com.aaa.service.scl.QuestionSclService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * 问题表(QuestionScl)表控制层
 *
 * @author makejava
 * @since 2022-08-30 18:45:23
 */
@RestController
@RequestMapping("questionScl")
public class QuestionSclController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private QuestionSclService questionSclService;

    //分页查询
    @RequestMapping(method = RequestMethod.GET, value = "/queryAll.do")
    @ResponseBody
    public Result queryAll(PageSortEntity pageSortEntity, QuestionScl questionScl) {
        Page pageResult = questionSclService.queryAll(pageSortEntity, questionScl);
        return success(pageResult.getResult(), pageResult.getTotal());
    }

    //添加
    @LogMonitor
    @RequestMapping("/insert.do")
    @ResponseBody
    public Result insert(QuestionScl questionScl, HttpSession session) {
        boolean user1 = questionSclService.insert(questionScl);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    //删除
    @LogMonitor
    @RequestMapping("/delete.do")
    @ResponseBody
    public Result delete(String id) {

        boolean delete = questionSclService.delete(id);
        if (delete) {
            return success();
        } else {
            return fail();
        }
    }

    //修改
    @LogMonitor
    @RequestMapping("/update.do")
    @ResponseBody
    public Result update(QuestionScl questionScl, HttpSession session) {
        boolean user1 = questionSclService.update(questionScl);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    //添加时查询是否重名
    @ResponseBody
    @GetMapping("repetitionName.do")
    public Result repetitionName(QuestionScl questionScl) {
        boolean b = this.questionSclService.repetitionName(questionScl);
        if (b) {
            return success("问题可用");
        }
        return fail("问题重复，不可用");
    }
    //ID 唯一性校验
    @ResponseBody
    @RequestMapping("/repetitionID.do")
    public Result repetitionID(QuestionScl questionScl) {
        if (ObjectUtil.isEmpty(questionScl.getId())) {
            return fail("不能为空");
        } else {
            boolean b = questionSclService.repetitionID(questionScl);
            if (b) {
                return success("ID可用");
            }
            return fail("ID重复不可用");
        }
    }

}

